<?php

// include("grafikcounter.php");
//$datei = ($_REQUEST['datei']);
//echo $datei;

if ((($_FILES["datei"]["type"] == "image/gif")
|| ($_FILES["datei"]["type"] == "image/jpeg")
|| ($_FILES["datei"]["type"] == "image/jpg"))
&& ($_FILES["datei"]["size"] < 4500000))
  {
  if ($_FILES["datei"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["datei"]["error"] . "<br />";
    }
  else
    {
   	 //echo "Upload: " . $_FILES["datei"]["name"] . "<br />";
    //echo "Type: " . $_FILES["datei"]["type"] . "<br />";
    //echo "Size: " . ($_FILES["datei"]["size"] / 1024) . " Kb<br />";
    //echo "Temp file: " . $_FILES["datei"]["tmp_name"] . "<br />";

    if (file_exists("uploads/" . $_FILES["datei"]["name"]))
      {
      //echo $_FILES["datei"]["name"] . " already exists!! ";
      }
    else
      { 
      move_uploaded_file($_FILES["datei"]["tmp_name"],
      "uploads/" .  basename($_FILES["datei"]["name"]));
      $_FILES['image']['type'] = image_type_to_mime_type(exif_imagetype(basename($_FILES["datei"]["name"])));
	  //echo "Stored in: " . "uploads/" . $_FILES["datei"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file Type!";
  }
  
  //$name	= "uploads/".$_FILES["datei"]["name"];
  //echo	$name;
  //echo"<IMG SRC=$name height='166' width='200' alt='badge photo'>";
  //echo"<IMG SRC='/uploads/driver.jpg'>";
 $imagepath=("uploads/" . $_FILES["datei"]["name"]);
 $ext = strtolower(end(explode('.',$imagepath)));
//set mime type content

header('Content-Type: image/jpeg');


//create original image
 switch ($ext) {
        case 'jpg':
        case 'jpeg':
                    $image = imagecreatefromjpeg($imagepath) ; 
        break;
        case 'gif':
                    $image = imagecreatefromgif($imagepath) ; 
        break;
        case 'png':
                    $image = imagecreatefrompng($imagepath) ; 
        break;
    } 
//$image = imagecreatefromjpeg($imagepath);

//get image dimension

$dim=getimagesize($imagepath);


//Set thumb dimension

$thumbw = 207;
$thumbh = 166;

//create empty image

$thumb_image=imagecreatetruecolor($thumbw, $thumbh);

//Resize original image and copy it to thumb image

imagecopyresampled($thumb_image, $image, 0, 0, 0, 0,
					$thumbw, $thumbh, $dim[0], $dim[1]);


//display thumb image
imagejpeg($thumb_image);

  
?>
 
 
